<?php
namespace app\controller;

use app\BaseController;
use app\model\Banner;
use think\facade\Filesystem;
use think\facade\Request;

class toolController extends BaseController
{
    public function updateImage()
    {
        $file = request() -> file('file');

        if ($file == null) {
            return json(['data'=>[],'code'=>30001,'tips'=>'未上传图片']);
        }
        $temp = explode(".", $_FILES["file"]["name"]);
        $extension = end($temp);
        if (!in_array($extension, array("jpeg","jpg","png"))) {
            return json(['data'=>[],'code'=>30002,'tips'=>'上传图片不合法']);
        }
        $saveName = Filesystem::disk('photo') -> putFile('photo', $file);
        $host=Request::host(true);
        $url ='http://'.$host.str_replace('\\', '/', '/uploads/' . $saveName);
        return json(['data'=>['url'=>$url],'code'=>0,'tips'=>'ok']);
    }
}
